package com.micromall.admin;

import com.google.common.collect.Maps;
import com.micromall.repository.WithdrawApplyRecordMapper;
import com.micromall.service.WithdrawService;
import com.micromall.web.resp.ResponseEntity;
import org.apache.ibatis.session.RowBounds;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by zhangzx on 16/3/28.
 * 提现管理
 */
@RestController
@RequestMapping(value = "/admin")
public class AdminWithdrawController extends AdminBasicController {

	@Resource
	private WithdrawService           withdrawService;
	@Resource
	private WithdrawApplyRecordMapper withdrawRecordMapper;

	/**
	 * 提现申请列表
	 *
	 * @param status audit:审核中，through:已通过，not_through:未通过
	 * @return
	 */
	@RequestMapping(value = "/withdraw/list")
	public ResponseEntity<?> records(Integer status, @RequestParam(defaultValue = "1") int pageNo, Integer pageSize) {
		Map params = Maps.newHashMap();
		params.put("orderBy", "id desc");
		if (status != null) {
			params.put("status", status);
			/*switch (status) {
				case "audit":
					params.put("status", WithdrawStatus.待审核);
					break;
				case "through":
					params.put("status", WithdrawStatus.审核通过);
					break;
				case "not_through":
					params.put("status", WithdrawStatus.审核不通过);
					break;
				default:
					return ResponseEntity.Failure("参数错误");

			}*/
		}
		return ResponseEntity.SuccessPage(withdrawRecordMapper.selectAdminPage(params, new RowBounds(pageNo, resizeLimit(pageSize))));
	}

	/**
	 * 提现审核
	 *
	 * @param id 提现记录id
	 * @param auditlog 审核不通过原因
	 * @param agreed 审核是否通过：true:通过审核，false:不通过
	 * @return
	 */
	@RequestMapping(value = "/withdraw/audit")
	public ResponseEntity<?> audit(int id, String auditlog, boolean agreed) {
		withdrawService.withdrawAudit(id, auditlog, agreed);
		return ResponseEntity.Success();
	}

}
